package org.example.juc.question;

public class PrintInOrderSolution2 {
    private volatile int jobFinish = 0;

    public PrintInOrderSolution2() {

    }

    public void first(Runnable printFirst) throws InterruptedException {

        // printFirst.run() outputs "first". Do not change or remove this line.
        printFirst.run();
        jobFinish = 1;
    }

    public void second(Runnable printSecond) throws InterruptedException {

        while (jobFinish!=1);
        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
        jobFinish = 2;
    }

    public void third(Runnable printThird) throws InterruptedException {

        // printThird.run() outputs "third". Do not change or remove this line.
        while (jobFinish!=2);
        printThird.run();
    }
}
